#!/usr/bin/perl -w

package XmlSaxParser;

use strict;
use XML::Parser;

use Exporter;
our @ISA=qw/Exporter/;
our @EXPORT=qw//;
our @EXPORT_OK=qw/ParseFile ParseData/;

sub Init;
sub Final;
sub Start;
sub End;
sub Char;
sub Comment;
sub CdataStart;
sub CdataEnd;

sub ParseData
{
	my $data=shift;
	my $parser=new XML::Parser(Handlers=>{
			Init=>\&Init,
			Start=>\&Start,
			End=>\&End,
			Char=>\&Char,
			Comment=>\&Comment,
			CdataStart=>\&CdataStart,
			CdataEnd=>\&CdataEnd,
			Final=>\&Final

		});
	$parser->parse($data);
}

sub ParseFile
{
	my $file=shift;
	my $parser=new XML::Parser(Handlers=>{
			Init=>\&Init,
			Start=>\&Start,
			End=>\&End,
			Char=>\&Char,
			Comment=>\&Comment,
			CdataStart=>\&CdataStart,
			CdataEnd=>\&CdataEnd,
			Final=>\&Final

		});
	$parser->parsefile($file);
}

sub Init
{
	print "Init\n";
}

sub Final
{
	print "Final\n";
}

sub Start
{
	my $expat=shift;
	my $tag=shift;
	my %hash;
	my $key;
	my $value;
	while(my $key=shift)
	{
		$value=shift;
		$hash{$key}=$value;
	}
	print "Start,tag=$tag\n";
}

sub End
{
	my $expat=shift;
	my $tag=shift;
	print "End,tag=$tag\n";
}

sub Char
{
	my $expat=shift;
	my $text=shift;
	$text=~s/\s/"Blank"/g;
	print "Char,text=$text\n";
}

sub Comment
{
	print "Comment\n";
}

sub CdataStart
{
	print "CdataStart\n";
}

sub CdataEnd
{
	print "CdataEnd\n";
}



1;

